package com.example.util;

import com.alibaba.fastjson.JSONObject;

/**
 * @Classname Results
 * @Description TODO
 * @Date 2022/5/13 23:24
 * @Created by XiongXiong
 * @Author: X.I.O
 */
public class Results {

    public static JSONObject success(){
        JSONObject obj=getJsObject();
        obj.put("code",0);
        obj.put("msg","success");
        return obj;
    }

    public static JSONObject success(Object obj){
        JSONObject json=success();
        json.put("data",obj);
        return json;
    }

    public static JSONObject success(String msg){
        JSONObject json=success();
        json.put("msg",msg);
        return json;
    }

    public static JSONObject success(String msg,Object data){
        JSONObject json=success();
        json.put("msg",msg);
        json.put("data",data);
        return json;
    }

    public static JSONObject error(){
        JSONObject jsonObject=getJsObject();
        jsonObject.put("code",1);
        jsonObject.put("msg","error");
        return jsonObject;
    }

    public static JSONObject error(String msg){
        JSONObject json=error();
        json.put("msg",msg);
        return json;
    }

    private static JSONObject getJsObject(){
        return new JSONObject();
    }
}
